# import datetime
#
# from django.contrib import admin
# from django.utils.html import format_html
#
# from nesun_cert_web.base_admin import BaseAdmin
# from nesun_cert_web.certification.models import ClientInfo, CertificationInfo

# Register your models here.
# class CertificationInfoInline(admin.TabularInline):
#     model = CertificationInfo
#     can_delete = False
#     show_change_link = True
#     fields= ('start_time', 'end_time', 'status', )
#     readonly_fields = ('start_time', )
#     verbose_name = verbose_name_plural = "用户历史认证信息"

# class ClientInfoAdmin(BaseAdmin):
#     list_display = ("client_id", "client_name", "colored_status", "add_time", )
#     # list_editable = ('status', )
#     # fields = ('client_name', 'client_cpu', 'client_mac', 'client_board', 'status')
#     readonly_fields = ('client_id', 'add_time', )
#     fieldsets = (
#         ("基本信息", {
#             'fields': (('client_id', 'client_name', ), )
#         }),
#         ('硬件信息', {
#             'fields': (('client_cpu', 'client_mac', 'client_board', ), )
#         }),
#         ('更多信息', {
#             'classes': ('collapse', ),
#             'fields': ('status', 'add_time', )
#         })
#     )

#     inlines = (CertificationInfoInline, )

#     # 筛选器
#     list_filter = ('client_name', 'status', )
#     search_fields = ('client_name', 'status', )
#     date_hierarchy = 'add_time'

#     # def get_queryset(self, request):
#     #     qs = super().get_queryset(request)
#     #     if request.user.is_superuser:
#     #         return qs
#     #     return qs.filter(author=request.user)

#     def _certifications(self, obj):
#         return obj.certifications_set.all()

# class CertificationInfoAdmin(BaseAdmin):
#     list_display = ("start_time", "end_time", "duration", "status", 'is_expired', )
#     list_editable = ('duration', )
#     fk_fields = ('client', )
#     readonly_fields = ('add_time', )
#     fieldsets = (
#         ("认证时间信息", {
#             "fields": (('start_time', 'end_time', 'duration', 'is_expired'), )
#         }),
#         ("认证信息", {
#             "fields": ('value', )
#         }),
#         ("更多信息", {
#             "classes": ('collapse', ),
#             "fields": ('status', 'add_time', 'client', )
#         })
#     )

#     # exclude = ("add_time", )

#     def expired(self, ps):
#         """自定义字段设置，根据认证终止时间判断认证是否过期"""
#         end_time = ps.end_time

#         if end_time > datetime.date.today():
#             ret = False
#             ret_display = '未过期'
#             color_code = 'green'
#         else:
#             ret = True
#             ret_display = '已过期'
#             color_code = 'red'
#         CertificationInfo.objects.filter(pk=ps.pk).update(is_expired=ret)
#         return format_html(
#             '<span style="color: {}">{}</span>',
#             color_code, ret_display
#         )
    
#     expired.short_description = "是否过期"

# admin.site.register(ClientInfo, ClientInfoAdmin)
# admin.site.register(CertificationInfo, CertificationInfoAdmin)